import 'package:flutter/material.dart';
import 'package:get/get.dart';

class AppDialog extends StatelessWidget {
  final String? title;
  final String message;
  final String? cancel;
  final String submit;
  final void Function()? onSubmit;
  final void Function()? onCancel;

  const AppDialog(
      {super.key,
      required this.title,
      required this.message,
      this.cancel,
      required this.submit,
      this.onSubmit,
      this.onCancel});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.white,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(padding: EdgeInsets.only(top: 18)),
          Visibility(
              visible: title != null,
              child: Container(child: Text(
                "$title",
                style: Get.textTheme.titleSmall?.copyWith(fontSize: 16),
              ), alignment: Alignment.center,).marginOnly(left: 16, right: 16)),
          Text(
            "$message",
            style: Get.textTheme.titleSmall?.copyWith(fontSize: 14),
          ).marginOnly(top: 20, left: 16, right: 16),
          Divider(
            height: 1,
            color: Get.theme.dividerColor,
          ).marginOnly(top: 32),
          Row(
            children: [
              Visibility(
                visible: cancel != null,
                child: Expanded(
                  child: TextButton(
                    style: TextButton.styleFrom(
                      foregroundColor: Color(0xff888888),
                    ),
                    onPressed: onCancel ??
                        () {
                          Get.closeAllDialogs();
                        },
                    child: Text("$cancel"),
                  ),
                ),
              ),
              Visibility(
                visible: cancel != null,
                child: Container(
                  width: 1 / Get.pixelRatio,
                  height: 36,
                  color: Get.theme.dividerColor,
                ),
              ),
              Expanded(
                child: TextButton(
                  style: TextButton.styleFrom(
                    foregroundColor: Get.theme.primaryColor,
                  ),
                  onPressed: onSubmit ??
                      () {
                        Get.closeAllDialogs();
                      },
                  child: Text("$submit"),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
